// n.d(e, { uL: () => u, Xy: () => l, sn: () => f });
import * as THREE from "three"
import i from "../other/947-34003"
import MeshBVH from "../mesh/MeshBVH"

export class BufferGeometryExt extends THREE.BufferGeometry {
  boundsTree: MeshBVH
}

const o = new THREE.Ray()
const a = new THREE.Matrix4()
const raycastBase = THREE.Mesh.prototype.raycast
function raycast(t: THREE.Raycaster, e: THREE.Intersection[]) {
  const that: THREE.Mesh<BufferGeometryExt, THREE.Material> = this
  if (that.geometry.boundsTree) {
    if (void 0 === that.material) return
    a.copy(that.matrixWorld).invert(), o.copy(t.ray).applyMatrix4(a)
    const n = that.geometry.boundsTree
    if (!0 === t["firstHitOnly"]) {
      const r = i.O(n.raycastFirst(o, that.material), that, t)
      r && e.push(r)
    } else {
      const r = n.raycast(o, that.material)
      for (let n = 0, s = r.length; n < s; n++) {
        const s = i.O(r[n], that, t)
        s && e.push(s)
      }
    }
  } else raycastBase.call(that, t, e)
}
function computeBoundsTree(t) {
  this.boundsTree = new MeshBVH(this, t)
  return this.boundsTree
}
function disposeBoundsTree() {
  this.boundsTree = null
}
export default {
  raycast,
  computeBoundsTree,
  disposeBoundsTree
}
